﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Globalization;

namespace DeleteExpensiveAlbums
{
    class DeleteExpensiveAlbums
    {
        static void Main()
        {
            const string SourceXML = @"..\..\..\catalog.xml";
            const decimal MaxAllowedPrice = 20;
            const string XmlCulture = "en-US";
            const string UpdatedXML = @"..\..\newCatalog.xml";

            XmlDocument doc = new XmlDocument();
            doc.Load(SourceXML);

            XmlNode rootNode = doc.DocumentElement;

            CultureInfo culture = new CultureInfo(XmlCulture);

            int changesMade = 0;

            foreach (XmlNode node in rootNode.ChildNodes)
            {
                decimal price = decimal.Parse(node["price"].InnerText, culture);
                if (price > MaxAllowedPrice)
                {
                    rootNode.RemoveChild(node);
                    changesMade++;
                }
            }
            doc.Save(UpdatedXML);
            if (changesMade > 0)
            {
                if (changesMade == 1)
                {
                    Console.WriteLine("1 album deleted!");
                }
                else
                {
                    Console.WriteLine("{0} albums deleted!", changesMade);
                }
            }
            else
            {
                Console.WriteLine("No changes made!");
            }
        }
    }
}
